//
//  MYGSelectUserCell.swift
//  MYDoctor
//
//  Created by Denny on 2024/4/29.
//

import UIKit

class MYGSelectUserCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    var model: MYGPatientList = MYGPatientList() {
        didSet {
            self.usernameLB.text = model.patient.name
            self.avatar.sd_setImage(with: URL(string: model.patient.avatar), placeholderImage: UIImage.init(named: "head"), context: nil)
            self.genderBtn.setTitle("\(model.patient.birthday.getAge())岁", for: .normal)
            if model.patient.gender == 1 {
                self.genderBtn.backgroundColor = UIColor.init(hexString: "#6985E3")
                self.genderBtn.setImage(UIImage(named: "common_male"), for: .normal)
            }else {
                self.genderBtn.backgroundColor = UIColor.init(hexString: "#F06A86")
                self.genderBtn.setImage(UIImage(named: "common_female"), for: .normal)
            }
//            var string = ""
//            for (_,obj) in model.images.enumerated() {
//                string = string + "[" +  obj.name + "]"
//            }
//            self.contentLB.text = string
        }
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        addSubview(avatar)
        avatar.snp.makeConstraints { make in
            make.size.equalTo(CGSize.init(width: 50, height: 50))
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(20)
        }
        addSubview(usernameLB)
        usernameLB.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(avatar.snp.right).offset(5)
            make.height.equalTo(25)
        }
        addSubview(genderBtn)
        genderBtn.snp.makeConstraints { make in
            make.centerY.equalTo(usernameLB.snp.centerY)
            make.left.equalTo(usernameLB.snp.right).offset(5)
            make.size.equalTo(CGSize.init(width: 45, height: 16))
        }
        
//        addSubview(contentLB)
//        contentLB.snp.makeConstraints { make in
//            make.top.equalTo(usernameLB.snp.bottom).offset(5)
//            make.left.equalTo(avatar.snp.right).offset(5)
//            make.right.equalToSuperview().offset(-25)
////            make.bottom.equalToSuperview()
//        }
        addSubview(line)
        line.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.right.equalToSuperview()
            make.left.equalTo(avatar.snp.right).offset(5)
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    var avatar:UIImageView = {
        let control = UIImageView()
        control.layer.cornerRadius = 25
        control.layer.masksToBounds = true
        return control
    }()
    
    var usernameLB:UILabel = {
        let control = UILabel()
        control.textColor = UIColor.init(hexString: "#2C2C2C")
        control.font = .medium(16)
        return control
    }()
    
    var contentLB:UILabel = {
        let control = UILabel()
        control.textColor = UIColor.init(hexString: "#808080")
        control.font = .regular(13)
        control.numberOfLines = 0
        return control
    }()
    
    var genderBtn:UIButton = {
        let control = UIButton()
        control.setTitleColor(.white, for: .normal)
        control.layer.cornerRadius = 4
        control.layer.masksToBounds = true
        control.titleLabel?.font = .regular(11)
        control.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0)
        return control
    }()
    
    var line: UIView = {
        let control = UIView()
        control.backgroundColor = UIColor.init(hexString: "#eeeeee")
        return control
    }()
}

